home *** CD-ROM | disk | FTP | other *** search
/ Aminet 43 / Aminet 43 (2001)(GTI - Schatztruhe)[!][Jun 2001].iso / Aminet / comm / tcp / rxsocket.lha / rxsocket / examples / whois.rexx < prev   
OS/2 REXX Batch file  |  2001-03-01  |  2KB  |  73 lines

  1. /*
  2.  * Name: whois.rexx 1.0 (18.02.01)
  3.  * Description: simple whois client with localization support
  4.  *
  5.  */
  6.  
  7. signal on break_c
  8.  
  9. l="rmh.library";if ~show("L",l) then;if ~addlib(l,0,-30) then exit
  10. l="locale.library";if ~show("L",l) then;if ~addlib(l,0,-30) then exit
  11. prg=ProgramName("NOEXT")
  12. call getStrings
  13. if ~open(stderr,"CONSOLE:","W") then stderr="STDOUT"
  14. if AddLibrary("rexxsupport.library","rxsocket.library")~=0 then call err strings.ERRCANTFIND "'"result"'",1
  15.  
  16. parm.0.value="rs.internic.net"
  17. if ~RMH_ReadArgs("HOST/K,TO/K,KEY/A/F") then do
  18.     call PrintFault()
  19.     exit
  20. end
  21.  
  22. if parm.1.flag then do
  23.     if ~open(out,parm.1.value,"W") then do
  24.         call PrintFault()
  25.         exit
  26.     end
  27. end
  28. else out="STDOUT"
  29.  
  30. s=socket("INET","STREAM")
  31. if s<0 then call err strings.ERRNOSOCKECT
  32.  
  33. remote.addraddr=resolve(parm.0.value)
  34. if remote.addraddr=="-1" then call err strings.ERRNOHOST "<"parm.0.value">",0
  35. remote.addrport=43
  36. if connect(s,"REMOTE")<0 then call err strings.ERRCANTCONNECT "<"parm.0.value">"
  37.  
  38. req="WHOIS" parm.2.value"D0A"x
  39. if send(s,req)~=length(req) then call err strings.ERRSEND
  40.  
  41. call writeln(out,strings.MSGRESULT "'"parm.2.value"'")
  42.  
  43. r=1
  44. do while r>0
  45.     r=recv(s,"BUF",256)
  46.     if r>0 then call writech(out,buf)
  47. end
  48. if r<0 then call err strings.ERRRECV
  49. exit
  50.  
  51. break_c:
  52.     say
  53.     call err "break"
  54.     exit
  55.  
  56. err:
  57. parse arg msg,ntdoerr
  58.     if ntdoerr~=0 then msg=msg "("ErrorString()")"
  59.     call writeln(stderr,prg":" msg)
  60.     exit
  61.  
  62. getStrings: procedure expose prg strings.
  63.     catalog=OpenCatalog(prg".catalog","english",0)
  64.     strings.ERRCANTFIND=GetCatalogStr(catalog,1,"can't find")
  65.     strings.ERRNOSOCKET=GetCatalogStr(catalog,2,"can't create socket")
  66.     strings.ERRNOHOST=GetCatalogStr(catalog,3,"host not found")
  67.     strings.ERRCANTCONNECT=GetCatalogStr(catalog,4,"can't connect to")
  68.     strings.ERRSEND=GetCatalogStr(catalog,5,"error while sending request")
  69.     strings.MSGRESULT=GetCatalogStr(catalog,6,"Whois results for")
  70.     strings.ERRRECV=GetCatalogStr(catalog,7,"error while receiving")
  71.     call CloseCatalog(catalog);
  72.     return
  73.